<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>ATSadd</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="atonex.html" title="atonex" />
    <link rel="next" href="ATSaddnz.html" title="ATSaddnz" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">ATSadd</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="atonex.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="ATSaddnz.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="ATSadd"></a>
      <div class="titlepage"></div>
      <a id="IndexATSadd" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">ATSadd</span>
        </h2>
        <p>ATSadd —  uses the data from an ATS analysis file to perform additive synthesis.
        </p>
      </div>
      <div class="refsect1">
        <a id="idp90284944"></a>
        <h2>Description</h2>
        <p>
            <span class="emphasis"><em>ATSadd</em></span> reads from an ATS analysis file and uses the data to perform additive synthesis using an internal array of interpolating oscillators.
        </p>
      </div>
      <div class="refsect1">
        <a id="idp90286640"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">ar <span class="command"><strong>ATSadd</strong></span> ktimepnt, kfmod, iatsfile, ifn, ipartials[, ipartialoffset, \
        ipartialincr, igatefn]</pre>
      </div>
      <div class="refsect1">
        <a id="idp90288864"></a>
        <h2>Initialization</h2>
        <p>
            <span class="emphasis"><em>iatsfile</em></span> – the ATS number (n in ats.n) or the name in quotes of the analysis file made using <a class="ulink" href="http://www-ccrma.stanford.edu/~juan/ATS.html" target="_top"><em class="citetitle">ATS</em></a>.
        </p>
        <p>
            <span class="emphasis"><em>ifn</em></span> – table number of a stored function containing a sine wave for <span class="emphasis"><em>ATSadd</em></span> and a cosine for <a class="link" href="ATSaddnz.html" title="ATSaddnz"><em class="citetitle">ATSaddnz</em></a> (see examples below for more info)
        </p>
        <p><span class="emphasis"><em>ipartials</em></span> – number of partials that will be used in the resynthesis (the noise has a maximum of 25 bands)
        </p>
        <p><span class="emphasis"><em>ipartialoffset</em></span> (optional) – is the first partial used (defaults to 0).
        </p>
        <p><span class="emphasis"><em>ipartialincr</em></span> (optional) – sets an increment by which these synthesis opcodes counts up from <span class="emphasis"><em>ipartialoffset</em></span> for ibins components in the re-synthesis (defaults to 1).
        </p>
        <p><span class="emphasis"><em>igatefn</em></span> (optional) – is the number of a stored function which will be applied to the amplitudes of the analysis bins before resynthesis takes place. If <span class="emphasis"><em>igatefn</em></span> is greater than 0 the amplitudes of each bin will be scaled by <span class="emphasis"><em>igatefn</em></span> through a simple mapping process. First, the amplitudes of all of the bins in all of the frames in the entire analysis file are compared to determine the maximum amplitude value. This value is then used to create normalized amplitudes as indices into the stored function <span class="emphasis"><em>igatefn</em></span>. The maximum amplitude will map to the last point in the function. An amplitude of 0 will map to the first point in the function. Values between 0 and 1 will map accordingly to points along the function table. See the examples below.
        </p>
      </div>
      <div class="refsect1">
        <a id="idp90299728"></a>
        <h2>Performance</h2>
        <p><span class="emphasis"><em>ktimepnt</em></span> – The time pointer in seconds used to index the ATS file. Used for <span class="emphasis"><em>ATSadd</em></span> exactly the same as for <a class="link" href="pvoc.html" title="pvoc"><em class="citetitle">pvoc</em></a>.</p>
        <p><span class="emphasis"><em>ATSadd</em></span> and <a class="link" href="ATSaddnz.html" title="ATSaddnz"><em class="citetitle">ATSaddnz</em></a> are based on <a class="link" href="pvadd.html" title="pvadd"><em class="citetitle">pvadd</em></a> by Richard Karpen and use files created by Juan Pampin's ATS (<a class="ulink" href="http://www-ccrma.stanford.edu/~juan/ATS.html" target="_top"><em class="citetitle">Analysis - Transformation - Synthesis</em></a>).
        </p>
        <p><span class="emphasis"><em>kfmod</em></span> – A control-rate transposition factor: a value of 1 incurs no transposition, 1.5 transposes up a perfect fifth, and .5 down an octave. Used for <span class="emphasis"><em>ATSadd</em></span> exactly the same as for <a class="link" href="pvoc.html" title="pvoc"><em class="citetitle">pvoc</em></a>.
        </p>
        <p><span class="emphasis"><em>ATSadd</em></span> reads from an ATS analysis file and uses the data to perform additive synthesis using an internal array of interpolating oscillators. The user supplies the wave table (usually one period of a sine wave), and can choose which analysis partials will be used in the re-synthesis.
        </p>
      </div>
      <div class="refsect1">
        <a id="idp90309696"></a>
        <h2>Examples</h2>
        <pre class="programlisting">  ktime <span class="opc">line</span>   0, p3, 2.5
  asig  <span class="opc">ATSadd</span> ktime, 1, "clarinet.ats", 1, 20, 2
        </pre>
        <p>In the example above, <span class="emphasis"><em>ipartials</em></span> is 20 and <span class="emphasis"><em>ipartialoffset</em></span> is 2. This will synthesize the 3rd thru 22nd partials in the "clarinet.ats" analysis file. <span class="emphasis"><em>kfmod</em></span> is 1 so there will be no pitch transformation. Since the <span class="emphasis"><em>ktimepnt</em></span> envelope moves from 0 to 2.5 over the duration of the note, the analysis file will be read from 0 to 2.5 seconds of the original duration of the analysis over the duration of the csound note, this way we can change the duration independent of the pitch.
        </p>
      </div>
      <div class="refsect1">
        <a id="idp90315168"></a>
        <h2>Examples</h2>
        <p>
      Here is a complete example of the ATSadd opcode. It uses the file <a class="ulink" href="examples/ATSadd.csd" target="_top"><em class="citetitle">ATSadd.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp90317040"></a>
          <p class="title">
            <strong>Example 59. Example of the ATSadd opcode.</strong>
          </p>
          <div class="example-contents">
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac     <span class="comment">;;;RT audio out</span>
<span class="comment">;-iadc    ;;;uncomment -iadc for RT audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o ATSadd.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span> <span class="op">=</span> 1

<span class="oblock">instr</span> 1	<span class="comment">; "beats.ats" is created by atsa</span>

ktime	<span class="opc">line</span>	0, p3, 2
asig	<span class="opc">ATSadd</span>	ktime, 1,  "beats.ats", 1, 20, 0, 2
	<span class="opc">outs</span>	asig<span class="op">*</span>3, asig<span class="op">*</span>3	<span class="comment">;amplify</span>

<span class="oblock">endin</span>


<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="comment">;sine wave.</span>
<span class="stamnt">f</span> 1 0 16384 10 1

<span class="stamnt">i</span> 1 0 2 
<span class="stamnt">e</span>

<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
        <p>In the above example we synthesize 20 partials as in example 1 except this time we're using a <span class="emphasis"><em>ipartialoffset</em></span> of 0 and <span class="emphasis"><em>ipartialincr</em></span> of 2, which means that we'll start from the first partial and synthesize 20 partials total, skipping every other one (ie. partial 1, 3, 5,..).
        </p>
        <p>
      Here is another example of the ATSadd opcode. It uses the file <a class="ulink" href="examples/ATSadd-2.csd" target="_top"><em class="citetitle">ATSadd-2.csd</em></a>.
      </p>
        <div class="example">
          <a id="idp90321488"></a>
          <p class="title">
            <strong>Example 60. Example 2 of the ATSadd opcode.</strong>
          </p>
          <div class="example-contents">
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
-odac -d -m1
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>
<span class="comment">;example by joachim heintz</span>
<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span> <span class="op">=</span> 1

giSine    <span class="ohdr">ftgen</span>     0, 0, 1024, 10, 1

  <span class="oblock">instr</span> AllTheTones
Sfile     <span class="op">=</span>         "fox.ats"
          <span class="opc">prints</span>    "Resynthesizing with all the tones.\n"
iDur      <span class="opc">ATSinfo</span>   Sfile, 7
p3        <span class="op">=</span>         iDur
iNumParts <span class="opc">ATSinfo</span>   Sfile, 3
          <span class="opc">prints</span>    "Overall number of <span class="opc">partials</span> <span class="op">=</span> <span class="op">%</span>d\n", iNumParts
ktime     <span class="opc">line</span>      0, iDur, iDur
asig      <span class="opc">ATSadd</span>    ktime, 1, Sfile, giSine, iNumParts
          <span class="opc">outs</span>      asig, asig

<span class="comment">;start next instr</span>
          <span class="opc">event_i</span>   "i", "TonesInBandsOfTen", iDur<span class="op">+</span>1, iDur, 0, iNumParts
  <span class="oblock">endin</span>

  <span class="oblock">instr</span> TonesInBandsOfTen
Sfile     <span class="op">=</span>         "fox.ats"
iOffset   <span class="op">=</span>         p4 <span class="comment">;start at this partial</span>
iNumParts <span class="op">=</span>         p5 <span class="comment">;overall number of partials</span>
          <span class="opc">prints</span>    "Resynthesizing with <span class="opc">partials</span> <span class="op">%</span>d <span class="op">-</span> <span class="op">%</span>d.\n", iOffset<span class="op">+</span>1, iOffset<span class="op">+</span>10
ktime     <span class="opc">line</span>      0, p3, p3
asig      <span class="opc">ATSadd</span>    ktime, 1, Sfile, giSine, 10, iOffset
          <span class="opc">outs</span>      asig, asig

<span class="comment">;start next instance until there are enough partials left</span>
 <span class="octrl">if</span> iOffset<span class="op">+</span>20 <span class="op">&lt;</span> iNumParts then
          <span class="opc">event_i</span>   "i", "TonesInBandsOfTen", p3<span class="op">+</span>1, p3, iOffset<span class="op">+</span>10, iNumParts
          <span class="octrl">else</span>
          <span class="opc">event_i</span>   "i", "End", p3, 1
 <span class="octrl">endif</span>
  <span class="oblock">endin</span>

  <span class="oblock">instr</span> End
          <span class="opc">exitnow</span>
  <span class="oblock">endin</span>
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">i</span> "AllTheTones" 0 1
<span class="stamnt">e</span> 999
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
      </div>
      <div class="refsect1">
        <a id="idp90323408"></a>
        <h2>See also</h2>
        <p><a class="link" href="ATSread.html" title="ATSread"><em class="citetitle">ATSread</em></a>, 
            <a class="link" href="ATSreadnz.html" title="ATSreadnz"><em class="citetitle">ATSreadnz</em></a>, 
            <a class="link" href="ATSinfo.html" title="ATSinfo"><em class="citetitle">ATSinfo</em></a>, 
            <a class="link" href="ATSbufread.html" title="ATSbufread"><em class="citetitle">ATSbufread</em></a>, 
            <a class="link" href="ATScross.html" title="ATScross"><em class="citetitle">ATScross</em></a>, 
            <a class="link" href="ATSinterpread.html" title="ATSinterpread"><em class="citetitle">ATSinterpread</em></a>, 
            <a class="link" href="ATSpartialtap.html" title="ATSpartialtap"><em class="citetitle">ATSpartialtap</em></a>, 
            <a class="link" href="ATSaddnz.html" title="ATSaddnz"><em class="citetitle">ATSaddnz</em></a>, 
            <a class="link" href="ATSsinnoi.html" title="ATSsinnoi"><em class="citetitle">ATSsinnoi</em></a></p>
      </div>
      <div class="refsect1">
        <a id="idp90332880"></a>
        <h2>Credits</h2>
        <p>
            </p>
        <table border="0" summary="Simple list" class="simplelist">
          <tr>
            <td>Author: Alex Norman</td>
          </tr>
          <tr>
            <td>Seattle,Washington</td>
          </tr>
          <tr>
            <td>2004</td>
          </tr>
        </table>
        <p>
        </p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="atonex.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="ATSaddnz.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">atonex </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> ATSaddnz</td>
        </tr>
      </table>
    </div>
  </body>
</html>
